//
//  MKUIFillingLayoutConstraint.h
//  MKUI
//	布局时,有一个填充元素,它在其他元素布局结束之后,填充剩下的空间
//  Created by sushangjin on 16/6/23.
//  Copyright © 2016年 sushangjin. All rights reserved.
//

#import "MKUILayoutConstraint.h"
NS_ASSUME_NONNULL_BEGIN
@interface MKUIFillingLayoutConstraint : MKUILayoutConstraint
@property(nonatomic,assign) MKUILayoutConstraintDirection layoutDirection;//布局方向.默认为MKUILayoutConstraintDirectionVertical
@property(nonatomic,assign) MKUILayoutConstraintVerticalAlignment layoutVerticalAlignment;//所有元素作为一个整体,在垂直方向上的位置,以及每一个元素在整体内的垂直方向上的对齐方式.默认为MKUILayoutConstraintVerticalAlignmentCenter

@property(nonatomic,assign) MKUILayoutConstraintHorizontalAlignment layoutHorizontalAlignment;//所有元素作为一个整体,在水平方向上的位置,以及每一个元素在整体内的水平方向上的对方方式.默认为MKUILayoutConstraintHorizontalAlignmentCenter

@property(nonatomic,assign) UIEdgeInsets contentInsets;//内边距,默认为(0,0,0,0)
@property(nonatomic,assign) CGFloat interitemSpacing;//元素间的间隔,默认为0
@property(nonatomic,strong,nullable) id<MKUILayoutConstraintItemProtocol> fillingItem;//被填充的元素,它会在最后才进行布局,尺寸等于剩下的空白区域
/**
 *  计算最合适的尺寸
 *
 *  @param size        外层限制
 *  @param resizeItems 是否计算子元素的最合适尺寸。YES：调用子元素的sizeThatFits方法。NO：直接使用子元素的bounds.size
 *
 *  @return 最合适的尺寸
 */
- (CGSize)sizeThatFits:(CGSize)size resizeItems:(BOOL)resizeItems;

/**
 *  对子元素进行布局
 *
 *  @param resizeItems 在布局前,是否让每个子元素自动调整到合适的尺寸
 */
- (void)layoutItemsWithResizeItems:(BOOL)resizeItems;
@end

typedef enum : NSUInteger {
	MKUIFillingLayoutConstraint_H_C,
	MKUIFillingLayoutConstraint_H_T,
	MKUIFillingLayoutConstraint_H_B,
	MKUIFillingLayoutConstraint_V_C,
	MKUIFillingLayoutConstraint_V_L,
	MKUIFillingLayoutConstraint_V_R,
} MKUIFillingLayoutConstraintParam;
MKAS_EnumTypeCategories(MKUIFillingLayoutConstraintParam)
@interface MKUIFillingLayoutConstraint (InitMethod)
- (id)initWithItems:(nullable NSArray<id<MKUILayoutConstraintItemProtocol>> *)items fillingItem:(nullable id<MKUILayoutConstraintItemProtocol>)fillingItem constraintParam:(MKUIFillingLayoutConstraintParam)param contentInsets:(UIEdgeInsets)contentInsets interitemSpacing:(CGFloat)interitemSpacing;
@property(nonatomic,assign) MKUIFillingLayoutConstraintParam constraintParam;
+ (void)parseConstraintParam:(MKUIFillingLayoutConstraintParam)param layoutDirection:(MKUILayoutConstraintDirection *)layoutDirection layoutVerticalAlignment:(MKUILayoutConstraintVerticalAlignment *)layoutVerticalAlignment layoutHorizontalAlignment:(MKUILayoutConstraintHorizontalAlignment *)layoutHorizontalAlignment;
+ (MKUIFillingLayoutConstraintParam)constraintParamWithLayoutDirection:(MKUILayoutConstraintDirection)layoutDirection layoutVerticalAlignment:(MKUILayoutConstraintVerticalAlignment)layoutVerticalAlignment layoutHorizontalAlignment:(MKUILayoutConstraintHorizontalAlignment)layoutHorizontalAlignment;
@end
NS_ASSUME_NONNULL_END
/**
 *
 以下为layoutDirection,layoutVerticalAlignment,layoutHorizontalAlignment的6种组合:
 self.fillingItem = C
 MKUIFillingLayoutConstraint_H_C
 layoutDirection = MKUILayoutConstraintDirectionHorizontal;
 layoutVerticalAlignment = MKUILayoutConstraintVerticalAlignmentCenter;
 :
  ______________
 |                              |
 |   B                         |
 |A B CC<------->CC|
 |   B                         |
 |_______________|
 
 MKUIFillingLayoutConstraint_H_T
 layoutDirection = MKUILayoutConstraintDirectionHorizontal;
 layoutVerticalAlignment = MKUILayoutConstraintVerticalAlignmentTop;
 :
  ______________
 |A B CC<------->CC|
 |   B                        |
 |   B                        |
 |                              |
 |_______________|
 
 MKUIFillingLayoutConstraint_H_B
 layoutDirection = MKUILayoutConstraintDirectionHorizontal;
 layoutVerticalAlignment = MKUILayoutConstraintVerticalAlignmentBottom;
 :
  _______________
 |                               |
 |                               |
 |    B                         |
 |    B                         |
 |A_B_CC<------->CC|
 
 MKUIFillingLayoutConstraint_V_C
 layoutDirection = MKUILayoutConstraintDirectionVertical;
 layoutHorizontalAlignment = MKUILayoutConstraintHorizontalAlignmentCenter;
 :
  ____
 |    A   |
 | BBB |
 |    C  |
 |    C  |
 |__C_|
 
 MKUIFillingLayoutConstraint_V_L
 layoutDirection = MKUILayoutConstraintDirectionVertical;
 layoutHorizontalAlignment = MKUILayoutConstraintHorizontalAlignmentLeft;
 :
  ____
 |  A     |
 |BBB  |
 |  C    |
 |  C    |
 |_C__|
 
 MKUIFillingLayoutConstraint_V_R
 layoutDirection = MKUILayoutConstraintDirectionVertical;
 layoutHorizontalAlignment = MKUILayoutConstraintHorizontalAlignmentRight;
 :
  ____
 |     A  |
 |  BBB|
 |     C |
 |     C |
 |__ C|
 */
